<template>
  <div class="tags-view">
    <el-tag
      v-for="tag in visitedViews"
      :key="tag.path"
      closable
      @close="closeTag(tag)"
      @click="go(tag)"
    >
      {{ tag.meta.title }}
    </el-tag>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'

const router = useRouter()
const visitedViews = ref([])

const go = (tag) => {
  router.push(tag.path)
}
const closeTag = (tag) => {
  visitedViews.value = visitedViews.value.filter(v => v.path !== tag.path)
}
</script>

<style scoped>
.tags-view {
  padding: 5px 10px;
  background: #fff;
  border-bottom: 1px solid #eee;
}
</style>
